<?php
	$TEMP->set_file(array('handle' => DIR_VIEW_DEAN . 'facultySchedules.html'));
	
	$FID 	= _GET('fid');
	
	if (!empty($FID)) {
		$faculty = $PI->getPersonalInformation($FID);
		$profName = $faculty['first_name'] . ' ' . $faculty['last_name'];
	}
	
	$profSubjectSchedulesIfHaveSched = $STUD->getProfSubjectSchedulesIfHaveSched($FID);
	
	$saveSched = 0;
	if ( $profSubjectSchedulesIfHaveSched == 0 ) {
		if ( isset($_POST['subButton']) ) {
			$STUD->getProfSubjectLabLecHours($FID, $strAccDept, $activeYear);
			$saveSched = 1;
		}
		$displayNone = '';
	}
	else {
		$displayNone = 'display-none';
	}
	
	$scheduleDefaultTime = $STUD->getScheduleDefaultTime(array('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'), $activeYear);
	
	$timeCount = 0;
	$bgcolor 	= LOOPING_F0F;
	
	if (!empty($scheduleDefaultTime)) {
		$scheduleHTML = '<table width="0" border="0" cellspacing="0" cellpadding="0" class="schedule-table">
						 <tr>
							<td width="120" height="25" class="schedule-label schedule-label-right" colspan="3">&nbsp;</td>
							<td width="103" class="schedule-label schedule-label-right">Monday</td>
							<td width="103" class="schedule-label schedule-label-right">Tuesday</td>
							<td width="103" class="schedule-label schedule-label-right">Wenesday</td>
							<td width="103" class="schedule-label schedule-label-right">Thursday</td>
							<td width="103" class="schedule-label schedule-label-right">Friday</td>
							<td width="103" class="schedule-label">Saturday</td>
						 </tr>';
						 
		$timeScheduleFrom = $STUD->getTimeSchedule('sched_from', $activeYear, 1);
		$timeScheduleTo   = $STUD->getTimeSchedule('sched_to', $activeYear, 1);
		
		//$timeScheduleFrom = array('7:30', '9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00');
		//$timeScheduleTo   = array('9:00', '10:30', '12:00', '1:00', '2:30', '4:00', '5:30', '7:00', '8:30');
	
		foreach($scheduleDefaultTime as $scheduleDayField => $scheduleDay) {
			$scheduleHTML .= '<tr align="center" ' . $bgcolor . '><td width="50" class="schedule-label-time"><div>' . date("h:i", strtotime($timeScheduleFrom[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleFrom[$timeCount])) . '</div></td><td width="20" class="schedule-label-time"> - </td><td width="50" class="schedule-label-time schedule-label-right"><div>' . date("h:i", strtotime($timeScheduleTo[$timeCount])) . '</div><div style="font-weight:normal; font-style:italic; font-size:12px;">' . date("a", strtotime($timeScheduleTo[$timeCount])) . '</div></td>';
			$rightCount = 1;
			$countDay   = count($scheduleDay);
			foreach($scheduleDay as $scheduleTimeField => $scheduleTime) {
				
				$clasRight = ($rightCount == $countDay) ? '' : 'schedule-time-right';
				
				if ($scheduleTime['sched_break'] == 'Y') {
					$sched = '<span class="font-red"><strong>LUNCH</strong></span>';
				}
				else {
					
					$profSubjectGenerateSchedules = $STUD->getProfSubjectGenerateSchedules($FID, $scheduleTime['sched_time_idPK']);

					$sched = '';
					if ( !empty($profSubjectGenerateSchedules) ) {
						//$lecLabBoth = ($profSubjectGenerateSchedules['lec_lab_both'] == '1') ? '(<em>lab</em>)' : '(<em>lec</em>)';
						switch($profSubjectGenerateSchedules['lec_lab_both']) {
							case '0': $lecLabBoth = '(<em>lec</em>)'; break;
							case '1': $lecLabBoth = '(<em>lab</em>)'; break;
							case '2': $lecLabBoth = '(<em>lec/lab</em>)'; break;
						}
						if ( $profSubjectGenerateSchedules['is_saturday'] == 'N' ) {
							$sched .= '<div><strong>' . $profSubjectGenerateSchedules['section_desc'] . '</strong></div>';
							$sched .= '<div>' . $profSubjectGenerateSchedules['room_desc'] . '</div>';
							$sched .= '<div>' . $lecLabBoth . '</div>';
						}
						$sched .= '<div><strong>' . $profSubjectGenerateSchedules['subj_code'] . '</strong></div>';
						$sched .= '<div class="schedule-active-value display-none" id="time' . $scheduleTime['sched_time_idPK'] . '" onclick="deleteSchedule(\'' . $profSubjectGenerateSchedules['prof_subj_sched_idPK'] . '\');">DELETE</div>';
					}
					else {
						$sched = '<div onclick="popupRequest(\'show\', \'SetFacultySchedule\', \'Faculty Schedule\', \'260\', \'500\', \'' . $scheduleTime['sched_time_idPK'] . '&fid=' . $FID . '\');" class="schedule-generate display-none" id="time' . $scheduleTime['sched_time_idPK'] . '">SET</br>SCHEDULE</div>';
					}
					
				}
				
				$scheduleHTML .= '<td class="schedule-time ' . $clasRight . '" height="75" align="center" onmouseover="setSchedule(\'' . $scheduleTime['sched_time_idPK'] . '\', \'show\')" onmouseout="setSchedule(\'' . $scheduleTime['sched_time_idPK'] . '\', \'hide\')"><div class="position-relative">' . $sched . '</div></td>';
				$rightCount++;
			}
			$scheduleHTML .= '</tr>';
			$bgcolor = ($bgcolor == LOOPING_F0F) ? LOOPING_FFF : LOOPING_F0F;
			$timeCount++;
		}
		$scheduleHTML .= '<tr><td height="5" colspan="3"></td><td colspan="9"></td></tr></table>';
	}
	else {
		$scheduleHTML = '<div class="change-section-button"><div class="set-time-schedule" onclick="setTimeSchedule(\'' . $activeYear . '\');">SET TIME FOR MONDAY - SATURDAY SCHEDULE</div></div><div id="set_time_schedule"></div>';
	}
	
	$TEMP->set_var(array('dean_sub_menu'	=> $pageLib->deanSubMenu(DIR_IMAGES),
						 'prof_name' 		=> $profName,
						 'time_table'		=> $scheduleHTML,
						 'save_sched'		=> $saveSched,
						 'fid'				=> $FID,
						 'diplay_none'		=> $displayNone,
						 'school_year'		=> $yearFrom . ' - ' . $yearTo,
						));
?>